﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MvcMusicStoreASPX.Models;

namespace MvcMusicStoreASPX.Controllers
{
    public class StoreController : Controller
    {
        MvcMusicStoreEntities entities = new MvcMusicStoreEntities();
        //
        // GET: /Store/

        public ActionResult Index()
        {
            var albums = entities.Albums.Include("Genre").Include("Artist").ToList();
            return View(albums);
        }

        //
        // GET: /Store/Details/5

        public ActionResult Details(int id)
        {
            return View();
        }

        //
        // GET: /Store/Create

        public ActionResult Create()
        {
            ViewBag.Genres = entities.Genres.OrderBy(g => g.Name).ToList();
            ViewBag.Artists = entities.Artists.OrderBy(a => a.Name).ToList();
            var album = new Album();
            return View(album);
        } 

        //
        // POST: /Store/Create

        [HttpPost]
        public ActionResult Create(Album album)
        {
            try
            {
                // TODO: Add insert logic here

                entities.Albums.Add(album);
                entities.SaveChanges();
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
        
        //
        // GET: /Store/Edit/5
 
        public ActionResult Edit(int id)
        {
            
            return View();
        }

        //
        // POST: /Store/Edit/5

        [HttpPost]
        public ActionResult Edit(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add update logic here
 
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /Store/Delete/5
 
        public ActionResult Delete(int id)
        {
            return View();
        }

        //
        // POST: /Store/Delete/5

        [HttpPost]
        public ActionResult Delete(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add delete logic here
 
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
    }
}
